package com.shop2cn.iapi.coupon.testcase.old;


import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import oracle.net.aso.a;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.coupon.parameter.BestGetProductUsableBatchResp;
import com.shop2cn.iapi.coupon.parameter.BestGetProductUsableBatchs;
import com.shop2cn.iapi.coupon.parameter.SellerCouponsList;
import com.shop2cn.iapi.coupon.parameter.getProductUsableBatchesBean;
import com.shop2cn.iapi.coupon.service.getProductUsableBatchesCall;
import com.shop2cn.iapi.couponmanage.parameter.CreateCouponBean;
import com.shop2cn.iapi.couponmanage.service.CreateCouponCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.CouponShop2cnMCallService;
import com.ymttest.database.model.couponbatch;
import com.ymttest.database.model.couponusecondition;
import com.ymttest.database.sqlwapper.couponbatchWapper;
import com.ymttest.database.sqlwapper.couponuseconditionWapper;
import com.ymttest.database.sqlwapper.couponWapper;
import com.ymttest.utils.TestDataManager;
/**
*全球优选--获取商品可用可领的优惠券批次id
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_getProductUsableBatches{
	private static getProductUsableBatchesBean bean;
	private static getProductUsableBatchesCall call;
	private couponbatchWapper batchWapper=new couponbatchWapper();
	private couponuseconditionWapper useconditionWapper=new couponuseconditionWapper();
	private couponWapper couponWapper=new couponWapper();
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("全球优选--获取商品可用可领的优惠券批次id");
	}

	@Before
	public void caseUp() {
		bean=new getProductUsableBatchesBean();
		call=new getProductUsableBatchesCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	private String str_subString(List<String> lst)
	{
		String str="";
		for(int i=0;i<lst.size();i++)
			str+=lst.get(i)+",";
		return str.substring(0, str.length()-1);
			
	}
   private String getDateString(Date date) {
        SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatter2 = new SimpleDateFormat("HH:mm:ss");

        return formatter1.format(date) + "T" + formatter2.format(date);
    }
	private List<String>  getValues(int batchId,int conditiionType)
	{
		List<couponusecondition>  act_usecondditions=useconditionWapper.selectByBatchId(batchId);
		
		List<String> values=act_usecondditions.stream().filter(a->a.getConditionType()==conditiionType)
				.map(b->b.getConditionValue()).collect(Collectors.toList());
	  return values;
	}
	private void check_couponbatch(couponbatch act_batch,BestGetProductUsableBatchResp exp)
	{
		//BestGetProductUsableBatchResp exp=exp_resp.get();
		Logger.verifyEquals(act_batch.getBatchId(), exp.getBatchId(), "验证 BatchId");
		Logger.verifyEquals(act_batch.getBatchCode(),exp.getBatchCode(), "验证 BatchId="+act_batch.getBatchId()+" 时BatchCode");
		
		Logger.verifyEquals(getDateString(act_batch.getAcquireStartTime()),exp.getAcquireStartTime(), "验证 BatchId="+act_batch.getBatchId()+" 时getAcquireStartTime");
		Logger.verifyEquals(getDateString(act_batch.getAcquireEndTime()),exp.getAcquireEndTime(), "验证 BatchId="+act_batch.getBatchId()+" 时getAcquireEndTime");
		Logger.verifyEquals(act_batch.getEffectiveType(),exp.getEffectiveType(), "验证 BatchId="+act_batch.getBatchId()+" 时getEffectiveType");
		Logger.verifyEquals(getDateString(act_batch.getValidStart()),exp.getValidStart(), "验证 BatchId="+act_batch.getBatchId()+" 时getValidStart");
		Logger.verifyEquals(getDateString(act_batch.getValidEnd()),exp.getValidEnd(), "验证 BatchId="+act_batch.getBatchId()+" 时getValidEnd");
		Logger.verifyEquals(act_batch.getEffectiveDays(),exp.getEffectiveDuration(), "验证 BatchId="+act_batch.getBatchId()+" 时EffectiveDuration");
		Logger.verifyEquals(act_batch.getEffectiveValidType(),exp.getEffectiveValidType(), "验证 BatchId="+act_batch.getBatchId()+" 时EffectiveTimeType");
		
		Logger.verifyEquals(act_batch.getCouponValue().stripTrailingZeros().toPlainString(),exp.getCouponValue().stripTrailingZeros().toPlainString(), "验证 BatchId="+act_batch.getBatchId()+" 时CouponValue");
		Logger.verifyEquals(act_batch.getMinOrderValue().stripTrailingZeros().toPlainString(),exp.getMinOrderValue().stripTrailingZeros().toPlainString(), "验证 BatchId="+act_batch.getBatchId()+" 时MinOrderValue");
		Logger.verifyEquals(act_batch.getReceiveTimesPerUser(),exp.getReceiveTimesPerUser(), "验证 BatchId="+act_batch.getBatchId()+" 时ReceiveTimesPerUser");
		//每个用户领取的数量
		int count=couponWapper.selectByBatchIdAndUserId(act_batch.getBatchId(), bean.getUserId()).size();
		Logger.verifyEquals(count,exp.getUserReceivedCount(), "验证 BatchId="+act_batch.getBatchId()+" 时UserReceivedCount");
		Logger.verifyEquals(act_batch.getUseConditionType(),exp.getUseConditionType(), "验证 BatchId="+act_batch.getBatchId()+" 时UseConditionType");
	}

	private void check_couponusecondition(List<String> values,couponbatch act_batch,BestGetProductUsableBatchResp exp)
	{
		if(act_batch.getUseConditionType()==5)
   		 Logger.verifyEquals("["+str_subString(values)+"]"
	    				,exp.getAllowCountryIds().toString(), "验证 BatchId="+act_batch.getBatchId()+" 时AllowCountryIds");	
   		else if(act_batch.getUseConditionType()==4)
		    		 Logger.verifyEquals("["+str_subString(values)+"]"
			    				,exp.getAllowCategoryIds().toString(), "验证 BatchId="+act_batch.getBatchId()+" 时AllowCategoryIds");
   		else if(act_batch.getUseConditionType()==3)
	    		 Logger.verifyEquals("["+str_subString(values)+"]"
		    				,exp.getAllowActivityIds().toString(), "验证 BatchId="+act_batch.getBatchId()+" 时AllowActivityIds");	
   		else if(act_batch.getUseConditionType()==6)
	    		 Logger.verifyEquals("["+str_subString(values)+"]"
		    				,exp.getAllowBrandIds().toString(), "验证 BatchId="+act_batch.getBatchId()+" 时AllowBrandIds");
   		else if(act_batch.getUseConditionType()==7)//国家+分类
   		{
   			//
   			values=getValues(act_batch.getBatchId(),5);//国家
   			Logger.verifyEquals("["+str_subString(values)+"]"
	    				,exp.getAllowCountryIds().toString(), "验证 BatchId="+act_batch.getBatchId()+" 时AllowCountryIds");
   			values=getValues(act_batch.getBatchId(),4);//分类
   			Logger.verifyEquals("["+str_subString(values)+"]"
		    				,exp.getAllowCategoryIds().toString(), "验证 BatchId="+act_batch.getBatchId()+" 时AllowCategoryIds");
   		}
   		else if(act_batch.getUseConditionType()==10)//品牌 + 活动
   		{
   			//
   		   values=getValues(act_batch.getBatchId(),5);//品牌
   		   Logger.verifyEquals("["+str_subString(values)+"]"
		    				,exp.getAllowBrandIds().toString(), "验证 BatchId="+act_batch.getBatchId()+" 时AllowBrandIds");
   		   values=getValues(act_batch.getBatchId(),3);//活动
   		   Logger.verifyEquals("["+str_subString(values)+"]"
		    				,exp.getAllowActivityIds().toString(), "验证 BatchId="+act_batch.getBatchId()+" 时AllowActivityIds");
   		}
	}
	
	private void check()
	{
		Logger.verifyEquals("0", call.getStatusCode1(), "验证返回Code");
	    Logger.verifyEquals("操作成功！",call.getMessage(), "验证返回Message");
	    //断言
	    BestGetProductUsableBatchs exp_batchs = call.getUsableBatchDtos();
	   	Map map = new HashMap();
	   	map.put("platformSource", bean.getPlatformId());
	    List<couponbatch>  act_batchs= batchWapper.getAllReceivablePlatformBatch(map);
	    
	    List<Integer> exp_batchIds = exp_batchs.getUsableBatchDtos().stream().map(b -> b.getBatchId()).collect(Collectors.toList());
	    
	    //查询使用条件
	    List<couponbatch> batchList=new ArrayList();
	    int count=0;
	    for(couponbatch act_batch:act_batchs)
	    {
	    	if(act_batch.getBatchId()==10194966)
	    	{
	    		Logger.comment("ok");
	    	}
    		List<String> values=null;
	    	if(act_batch.getUseConditionType()!=0 && act_batch.getUseConditionType()!=7)
	    	{
	    		//商品
	    		if(act_batch.getUseConditionType()==2)
	    		{
	    		  values=getValues(act_batch.getBatchId(),2);
	    		   if(values.contains(bean.getProductCode())==false)
	    			   continue;
	    		}

	    		//指定买手 
	    		if(act_batch.getUseConditionType()==1)
	    		{
	    		   values=getValues(act_batch.getBatchId(),1);
	    		   if(values.contains(String.valueOf(bean.getSellerId()))==false)
	    			   continue;
	    		}
	    
    			//指定国家
	    		if(act_batch.getUseConditionType()==5)
	    		{
	    		  values=getValues(act_batch.getBatchId(),5);
	    		   if(values.contains(String.valueOf(bean.getCountryId()))==false)
	    			   continue;
	    		}
	    		//指定分类 
	    		if(act_batch.getUseConditionType()==4)
	    		{
	    		   values=getValues(act_batch.getBatchId(),4);
	    		   if(values.contains(bean.getCategoryIds().get(0).toString())==false)
	    			   continue;
	    		} 
	    	 }
	    	
    		if(exp_batchIds.contains(act_batch.getBatchId()))
    		{
    			Optional<BestGetProductUsableBatchResp> exp_resp=exp_batchs.getUsableBatchDtos().stream()
    					.filter(e->e.getBatchId().equals(act_batch.getBatchId())).findFirst();
    			if(exp_resp==null)
    				Logger.verifyEquals(false,true, "验证 返回数据不正确，应该含有BatchId="+act_batch.getBatchId());
    			else
    			{
    				BestGetProductUsableBatchResp exp=exp_resp.get();
    				check_couponbatch(act_batch,exp);
    				check_couponusecondition(values,act_batch,exp);
    			}
    			batchList.add(act_batch);
    			count++;
    		}
    		//else
    		  // Logger.comment("  "+act_batch.getBatchId());
	    }
	    Logger.verifyEquals(count, exp_batchs.getUsableBatchDtos().size(), "验证返回的数据与数据查询数据一致");
	    
	    //如此返回集合与数据库集合数量不一致，打印出相差的批次
	    List<Integer> _a = exp_batchs.getUsableBatchDtos().stream().map(a->a.getBatchId()).collect(Collectors.toList());
	    List<Integer> _b = batchList.stream().map(a->a.getBatchId()).collect(Collectors.toList());
	    for(Integer id:_a)
	    {
	    	if(!_b.contains(id))
	    		System.out.println("两集合相差的batchid： " + id);
	    }

	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProductUsableBatches_001() {
		Logger.start(true,"全球优选--获取商品可用可领的优惠券批次-指定商品优惠券-未过期");
		try {
            //创建优惠券
			int sellerId=Integer.parseInt(TestDataManager.getRandomNum(5));
			int userId=Integer.parseInt(TestDataManager.getRandomNum(5));
			String productId=TestDataManager.getRandomNum(5);
			Logger.comment("productId:  "+productId);
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			CreateCouponBean createcouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPlatformSource(1);
			//指定商品id
			List<String> productIds = new ArrayList<String>();
			productIds.add(productId);
			productIds.add("121231");
			createcouponBean.setProductIds(productIds);
		    CouponShop2cnMCallService.createPlatformCoupon(createcouponBean);

			Thread.sleep(2000);
			
			bean.setUserId(userId);
			bean.setUserType(1);//0：不限 1：新用户 2：老用户
			bean.setProductCode(productId);
			bean.setPlatformId(1);
			bean.setSellerId(sellerId);
			bean.setActivityId(0);
			
			List<Integer> categoryIds2 = new ArrayList<Integer>();
			categoryIds2.add(1);
			categoryIds2.add(2);
			categoryIds2.add(3);
			
			bean.setCategoryIds(categoryIds2);
			bean.setCountryId(1);
			bean.setIsPsp(true);
			bean.setBrandId(1);
			
			call.setData(bean);
			call.callService();		
			
			check();
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProductUsableBatches_002() {
		Logger.start(true,"全球优选--获取商品可用可领的优惠券批次-指定商品优惠券-已过期");
		try {
			 //创建优惠券
			int sellerId=Integer.parseInt(TestDataManager.getRandomNum(5));
			int userId=Integer.parseInt(TestDataManager.getRandomNum(5));
			String productId=TestDataManager.getRandomNum(5);
			Logger.comment("productId:  "+productId);
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			CreateCouponBean createcouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPlatformSource(1);
			//指定商品id
			List<String> productIds = new ArrayList<String>();
			productIds.add(productId);
			productIds.add("121231");
			createcouponBean.setProductIds(productIds);
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createcouponBean);
            Logger.comment("#####  设置优惠券批次过期 开始 ##########");
		    Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();

	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前一天
	        dBefore = calendar1.getTime(); // 得到前一天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为后十天
	        dAfter = calendar2.getTime(); // 得到前一天的时间
	        new couponbatchWapper().setAcquireStartTime(createCouponCall.getBatchCode(), dBefore);
	    	new couponbatchWapper().setAcquireEndTime(createCouponCall.getBatchCode(), dAfter);
	    	Logger.comment("#####  设置优惠券批次过期 结束 ##########");
			Thread.sleep(2000);
			
			bean.setUserId(userId);
			bean.setUserType(1);//0：不限 1：新用户 2：老用户
			bean.setProductCode(productId);
			bean.setPlatformId(1);
			bean.setSellerId(sellerId);
			bean.setActivityId(0);
			
			List<Integer> categoryIds2 = new ArrayList<Integer>();
			categoryIds2.add(1);
			categoryIds2.add(2);
			categoryIds2.add(3);
			
			bean.setCategoryIds(categoryIds2);
			bean.setCountryId(1);
			bean.setIsPsp(true);
			bean.setBrandId(1);
			
			call.setData(bean);
			call.callService();			
			
		    BestGetProductUsableBatchs exp_batchs = call.getUsableBatchDtos();
		    List<String> exp_batchIds = exp_batchs.getUsableBatchDtos().stream().map(b -> b.getBatchCode()).collect(Collectors.toList());
			Logger.verifyEquals(false, exp_batchIds.contains(createCouponCall.getBatchCode()), "验证过期优惠券批次不在返回列表中");    
		    
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProductUsableBatches_003() {
		Logger.start(true,"全球优选--获取商品可用可领的优惠券批次-指定商品优惠券-已删除");
		try {
			 //创建优惠券
			int sellerId=Integer.parseInt(TestDataManager.getRandomNum(5));
			int userId=Integer.parseInt(TestDataManager.getRandomNum(5));
			String productId=TestDataManager.getRandomNum(5);
			Logger.comment("productId:  "+productId);
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			CreateCouponBean createcouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPlatformSource(1);
			//指定商品id
			List<String> productIds = new ArrayList<String>();
			productIds.add(productId);
			productIds.add("121231");
			createcouponBean.setProductIds(productIds);
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createcouponBean);
            Logger.comment("#####  设置优惠券删除 开始 ##########");
	        new couponbatchWapper().setIsInvalid(createCouponCall.getBatchCode());
	    	Logger.comment("#####  设置优惠券批次删除 结束 ##########");
			Thread.sleep(2000);
			
			bean.setUserId(userId);
			bean.setUserType(1);//0：不限 1：新用户 2：老用户
			bean.setProductCode(productId);
			bean.setPlatformId(1);
			bean.setSellerId(sellerId);
			bean.setActivityId(0);
			
			List<Integer> categoryIds2 = new ArrayList<Integer>();
			categoryIds2.add(1);
			categoryIds2.add(2);
			categoryIds2.add(3);
			
			bean.setCategoryIds(categoryIds2);
			bean.setCountryId(1);
			bean.setIsPsp(true);
			bean.setBrandId(1);
			
			call.setData(bean);
			call.callService();			
			
		    BestGetProductUsableBatchs exp_batchs = call.getUsableBatchDtos();
		    List<String> exp_batchIds = exp_batchs.getUsableBatchDtos().stream().map(b -> b.getBatchCode()).collect(Collectors.toList());
			Logger.verifyEquals(false, exp_batchIds.contains(createCouponCall.getBatchCode()), "验证作废优惠券批次不在返回列表中");  		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProductUsableBatches_004() {
		Logger.start(true,"全球优选--获取商品可用可领的优惠券批次-指定商品优惠券-未过期，但全部领取");
		try {
			 //创建优惠券
			int sellerId=Integer.parseInt(TestDataManager.getRandomNum(5));
			int userId=Integer.parseInt(TestDataManager.getRandomNum(5));
			String productId=TestDataManager.getRandomNum(5);
			Logger.comment("productId:  "+productId);
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			CreateCouponBean createcouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPlatformSource(1);
			//指定商品id
			List<String> productIds = new ArrayList<String>();
			productIds.add(productId);
			productIds.add("121231");
			createcouponBean.setProductIds(productIds);
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createcouponBean);
            Logger.comment("#####  设置优惠券全部领取开始 ##########");
            couponbatch batch = new couponbatchWapper().selectBybatchCode(createCouponCall.getBatchCode()).get(0);
	        new couponbatchWapper().setiReceiveCount(batch.getBatchId(), batch.getTotalNum());
	    	Logger.comment("#####  设置优惠券全部领取 结束 ##########");
			Thread.sleep(2000);
			
			bean.setUserId(userId);
			bean.setUserType(1);//0：不限 1：新用户 2：老用户
			bean.setProductCode(productId);
			bean.setPlatformId(1);
			bean.setSellerId(sellerId);
			bean.setActivityId(0);
			
			List<Integer> categoryIds2 = new ArrayList<Integer>();
			categoryIds2.add(1);
			categoryIds2.add(2);
			categoryIds2.add(3);
			
			bean.setCategoryIds(categoryIds2);
			bean.setCountryId(1);
			bean.setIsPsp(true);
			bean.setBrandId(1);
			
			call.setData(bean);
			call.callService();			
			
		    BestGetProductUsableBatchs exp_batchs = call.getUsableBatchDtos();
		    List<String> exp_batchIds = exp_batchs.getUsableBatchDtos().stream().map(b -> b.getBatchCode()).collect(Collectors.toList());
			Logger.verifyEquals(false, exp_batchIds.contains(createCouponCall.getBatchCode()), "验证优惠券全部领取批次不在返回列表中");  			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProductUsableBatches_005() {
		Logger.start(true,"全球优选--获取商品可用可领的优惠券批次-平台通用优惠券-未过期");
		try {
			  //创建优惠券
			int sellerId=Integer.parseInt(TestDataManager.getRandomNum(5));
			int userId=Integer.parseInt(TestDataManager.getRandomNum(5));
			String productId=TestDataManager.getRandomNum(5);
			Logger.comment("productId:  "+productId);
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			CreateCouponBean createcouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPlatformSource(1);
			CreateCouponCall createCouponCall=CouponShop2cnMCallService.createPlatformCoupon(createcouponBean);

			Thread.sleep(2000);
			
			bean.setUserId(userId);
			bean.setUserType(1);//0：不限 1：新用户 2：老用户
			bean.setProductCode(productId);
			bean.setPlatformId(1);
			bean.setSellerId(sellerId);
			bean.setActivityId(0);
			
			List<Integer> categoryIds2 = new ArrayList<Integer>();
			categoryIds2.add(1);
			categoryIds2.add(2);
			categoryIds2.add(3);
			
			bean.setCategoryIds(categoryIds2);
			bean.setCountryId(1);
			bean.setIsPsp(true);
			bean.setBrandId(1);
			
			call.setData(bean);
			call.callService();		
			
			check();		
			
		    BestGetProductUsableBatchs exp_batchs = call.getUsableBatchDtos();
		    List<String> exp_batchIds = exp_batchs.getUsableBatchDtos().stream().map(b -> b.getBatchCode()).collect(Collectors.toList());
			Logger.verifyEquals(true, exp_batchIds.contains(createCouponCall.getBatchCode()), "验证刚创建的优惠券批次在返回列表中"); 
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProductUsableBatches_006() {
		Logger.start(true,"全球优选--获取商品可用可领的优惠券批次-平台通用优惠券-已过期");
		try {
			 //创建优惠券
			int sellerId=Integer.parseInt(TestDataManager.getRandomNum(5));
			int userId=Integer.parseInt(TestDataManager.getRandomNum(5));
			String productId=TestDataManager.getRandomNum(5);
			Logger.comment("productId:  "+productId);
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			CreateCouponBean createcouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPlatformSource(1);
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createcouponBean);
            Logger.comment("#####  设置优惠券批次过期 开始 ##########");
		    Date dNow = new Date(); // 当前时间
	        Date dBefore = new Date();
	        Date dAfter = new Date();

	        Calendar calendar1 = Calendar.getInstance(); // 得到日历
	        calendar1.setTime(dNow);// 把当前时间赋给日历
	        calendar1.add(Calendar.DAY_OF_MONTH, -10); // 设置为前一天
	        dBefore = calendar1.getTime(); // 得到前一天的时间

	        Calendar calendar2 = Calendar.getInstance(); // 得到日历
	        calendar2.setTime(dNow);// 把当前时间赋给日历
	        calendar2.add(Calendar.DAY_OF_MONTH, -1); // 设置为后十天
	        dAfter = calendar2.getTime(); // 得到前一天的时间
	        new couponbatchWapper().setAcquireStartTime(createCouponCall.getBatchCode(), dBefore);
	    	new couponbatchWapper().setAcquireEndTime(createCouponCall.getBatchCode(), dAfter);
	    	Logger.comment("#####  设置优惠券批次过期 结束 ##########");
			Thread.sleep(2000);
			
			bean.setUserId(userId);
			bean.setUserType(1);//0：不限 1：新用户 2：老用户
			bean.setProductCode(productId);
			bean.setPlatformId(1);
			bean.setSellerId(sellerId);
			bean.setActivityId(0);
			
			List<Integer> categoryIds2 = new ArrayList<Integer>();
			categoryIds2.add(1);
			categoryIds2.add(2);
			categoryIds2.add(3);
			
			bean.setCategoryIds(categoryIds2);
			bean.setCountryId(1);
			bean.setIsPsp(true);
			bean.setBrandId(1);
			
			call.setData(bean);
			call.callService();			
			
		    BestGetProductUsableBatchs exp_batchs = call.getUsableBatchDtos();
		    List<String> exp_batchIds = exp_batchs.getUsableBatchDtos().stream().map(b -> b.getBatchCode()).collect(Collectors.toList());
			Logger.verifyEquals(false, exp_batchIds.contains(createCouponCall.getBatchCode()), "验证过期优惠券批次不在返回列表中");    	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_getProductUsableBatches_007() {
		Logger.start(true,"全球优选--获取商品可用可领的优惠券批次-平台通用优惠券-已删除");
		try {
			 //创建优惠券
			int sellerId=Integer.parseInt(TestDataManager.getRandomNum(5));
			int userId=Integer.parseInt(TestDataManager.getRandomNum(5));
			String productId=TestDataManager.getRandomNum(5);
			Logger.comment("productId:  "+productId);
			CouponShop2cnMCallService CouponShop2cnMCallService = new CouponShop2cnMCallService();
			
			CreateCouponBean createcouponBean = CouponShop2cnMCallService.setDefaultPlatformCreateCouponBeanForRecieve();
			createcouponBean.setPlatformSource(1);
			CreateCouponCall createCouponCall= CouponShop2cnMCallService.createPlatformCoupon(createcouponBean);
            Logger.comment("#####  设置优惠券删除 开始 ##########");
	        new couponbatchWapper().setIsInvalid(createCouponCall.getBatchCode());
	    	Logger.comment("#####  设置优惠券批次删除 结束 ##########");
			Thread.sleep(2000);
			
			bean.setUserId(userId);
			bean.setUserType(1);//0：不限 1：新用户 2：老用户
			bean.setProductCode(productId);
			bean.setPlatformId(1);
			bean.setSellerId(sellerId);
			bean.setActivityId(0);
			
			List<Integer> categoryIds2 = new ArrayList<Integer>();
			categoryIds2.add(1);
			categoryIds2.add(2);
			categoryIds2.add(3);
			
			bean.setCategoryIds(categoryIds2);
			bean.setCountryId(1);
			bean.setIsPsp(true);
			bean.setBrandId(1);
			
			call.setData(bean);
			call.callService();			
			
		    BestGetProductUsableBatchs exp_batchs = call.getUsableBatchDtos();
		    List<String> exp_batchIds = exp_batchs.getUsableBatchDtos().stream().map(b -> b.getBatchCode()).collect(Collectors.toList());
			Logger.verifyEquals(false, exp_batchIds.contains(createCouponCall.getBatchCode()), "验证作废优惠券批次不在返回列表中"); 		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}